<div class="row">
	<div class="col-xs-12">
		<div class="row well well-sm">
			<div class="col-xs-12 col-sm-9 col-sm-offset-1"><?php
			echo form_open(null,array(
				'class'=>'form-horizontal','role'=>'form'
			));
				?><div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Tiêu đề:</label>
					<div class="col-sm-9 col-md-9 col-lg-10"><?php
						echo form_input(array(
							'name'=>'tieu-de','value'=>set_value('tieu-de',$news->getTitle()),
							'class'=>'form-control','required'=>'required',
							'placeholder'=>'Tiêu đề tin tức'
						));
						echo form_error('tieu-de');
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Hình đại diện:</label>
					<div class="col-sm-3 col-md-3">
						<span class="thumbnail" id="image_trigger" data-toggle="modal" data-target="#gallery_selector" data-url="<?php echo site_url(); ?>"><?php
							$img = $news->getThumbnail();
							if(empty($img)):
								$img = site_url('/assets/img/notfound.jpg');
								$val = null;
							else:
								$val = $img->getId();
								$img = site_url().'/assets/upload/'.$img->getName();
							endif;
							?><img src="<?php echo $img; ?>" />
						</span>
						<input type="hidden" id="avatar_image" name="thumb" value="<?php echo set_value('ten', $val); ?>" /><?php
						echo form_error('avatar_image');
					?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Nội dung:</label>
					<div class="col-sm-9 col-md-9 col-lg-10"><?php
						echo form_textarea(array(
							'name'=>'noi-dung','value'=>set_value('noi-dung',$news->getContent()),
							'class'=>'form-control bbcode',
							'placeholder'=>'Nội dung tin tức'
						));
						echo form_error('noi-dung');
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Tình trạng:</label>
					<div class="col-sm-9 col-md-9 col-lg-10"><?php
						echo '<label class="label label-warning">'.form_checkbox(array(
							'type'=>'radio','name'=>'active','style'=>'vertical-align:-3px',
							'value'=>'0','checked'=>set_checkbox('active','0')
						)).' Ẩn</label> &nbsp;&nbsp';
						echo '<label class="label label-success">'.form_checkbox(array(
							'type'=>'radio','name'=>'active','style'=>'vertical-align:-3px',
							'value'=>'1','checked'=>set_checkbox('active','1',true)
						)).' Hiện</label>';
						echo form_error('active');
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Nháp:</label>
					<div class="col-sm-9 col-md-9 col-lg-10"><?php
						echo '<label class="label label-warning">'.form_checkbox(array(
							'type'=>'radio','name'=>'stick','style'=>'vertical-align:-3px',
							'value'=>'0','checked'=>set_checkbox('stick','0')
						)).' Không</label> &nbsp;&nbsp';
						echo '<label class="label label-success">'.form_checkbox(array(
							'type'=>'radio','name'=>'stick','style'=>'vertical-align:-3px',
							'value'=>'1','checked'=>set_checkbox('stick','1',true)
						)).' Có</label>';
						echo form_error('stick');
					?></div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-5 col-md-offset-4 col-lg-offset-3 col-sm-7 col-md-8 col-lg-9"><?php
						echo form_submit(array(
							'name'=>'submit','value'=>'Sửa tin tức',
							'class'=>'btn btn-info'
						)).' '.form_reset(array(
							'name'=>'reset','value'=>'Nhập lại',
							'class'=>'btn btn-warning'
						));
					?></div>
				</div><?php
			echo form_close();
			?></div>
		</div>
	</div>
</div>
<div class="modal fade" id="gallery_selector" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Hình ảnh</h4>
      </div>
      <div class="modal-body">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Đóng</button>
        <button type="button" class="btn btn-primary" id="gallery_submit">Chọn hình</button>
      </div>
    </div>
  </div>
</div>
<script>
$('#gallery_selector').on('show.bs.modal', function (event) {
	$('#gallery_selector .modal-body').load($('#image_trigger').data('url')+"admin/gallery/");
});
$('#gallery_submit').click(function(e){
	var select = $('#gallery_selector .modal-body .ui-selected');
	if(select.length) {
		$('#avatar_image').val(select.data('id'));
		$('#image_trigger').find('img').attr('src', select.data('img')).fadeOut().fadeIn();
		$('#gallery_selector').modal('hide');
	} else
		e.stopImmediatePropagation();
});
$('.bbcode').sceditor({
	toolbarExclude :'emoticon,cut,copy,paste,print',
	//toolbar:'bold,commandasd,source',
	emoticonsEnabled:false,
	plugins:"bbcode",
	style:"<?php echo base_url('/assets/css/default.min.css'); ?>"
});
</script>